/*
 *  SFClib - Secure File Container Library
 *
 *  sfclib.h - Copyright(c) 2009 The SFCLib authors
 *
 *  The original author of this file is: Roberto Estrada Casarrubios.
 *
 *	This file is part of SFClib.
 *
 *  SFClib is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU Lesser General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  SFClib is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public License
 *  along with SFClib.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef SFCLIB_H
#define SFCLIB_H

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#ifdef WINDOWS
#include <windows.h>
#define uint64 UINT64
#define uint32 UINT32
#ifdef SFCLIB_BUILD
#define SFCAPI extern __declspec(dllexport)
#else
#define SFCAPI extern __declspec(dllimport)
#endif
#else
#define SFCAPI extern
#endif

#ifdef __cplusplus
extern "C" {
#endif

/*
 * @fn	SFCAPI int createSFC(char* name, char* path)
 * 
 * @brief	Creates a new SFC file with the given name in the specified
 *			path.
 * 
 * @author	Roberto Estrada Casarrubios
 * 
 * @param	fullpath   The full pathname where the file will be created.
 * @param	key		The key which decrypts the contents of the file.
 * 
 * @return	0 if succesful, -1 if any error occured. 
 */
SFCAPI int createSFC(char* fullpath, char* key);

/*
 * @fn	SFCAPI int openSFC(char* path, char* key)
 * 
 * @brief	Opens an SFC File in the given path. 
 * 
 * @author	Roberto Estrada Casarrubios
 * 
 * @param	path	The full pathname of the file, including name. 
 * @param	key		The key which decrypts the contents of the file. 
 * 
 * @return	0 if succesful, -1 if any error occured. Even if the key is
 *			wrong, it will return 0 too.
 */
SFCAPI int openSFC(char* path, char* key);

/*
 * @fn	SFCAPI int buildSFC()
 * 
 * @brief	Builds the SFC File. 
 * 
 * @author	Roberto Estrada Casarrubios
 * 
 * @return	0 if succesful, -1 if any error occured during the process.
 */
SFCAPI int buildSFC();

/*
 * @fn	SFCAPI uint32 sf_creat(char* name)
 * 
 * @brief	Creates a new file inside the SFC File 
 * 
 * @author	Roberto Estrada Casarrubios
 * 
 * @param	name The name of the file to create. 
 * 
 * @return	The unique 32-bit file descriptor, -1 if any error occured. 
 */
SFCAPI uint32 sf_creat(char* name);

/*
 * @fn	SFCAPI uint64 sf_open(char* name)
 * 
 * @brief	Opens a file inside the SFC File
 * 
 * @author	Roberto Estrada Casarrubios 
 * 
 * @param	name	If non-null, the name. 
 * 
 * @return	The 32 bit unique file descriptor for
 *			the	specified file.
 */
SFCAPI uint32 sf_open(char* name);

/*
 * @fn	SFCAPI int sf_read(uint64 fd,void* buf,int length)
 * 
 * @brief	Reads, decrypts and decompresses a file in the SFC
 *          and puts it in the destination file specified.
 * 
 * @author	Roberto Estrada Casarrubios
 * 
 * @param	fd			The file descriptor of the file to read. 
 * @param	file		The destination file where to put the contents of this file
 * 
 * @return	The number of bytes read, can be less than numBytes.
 */
SFCAPI int sf_read(uint32 fd,FILE *file);

/*
 * @fn	SFCAPI int sf_write(uint32 fd,FILE* file)
 * 
 * @brief	Writes the file contents to the SFC File 
 * 
 * @author	Roberto Estrada Casarrubios
 * 
 * @param	fd		The file descriptor in the SFC of the file to be written
 * @param	file	A pointer to the file to be written
 * 
 * @return	0 if succesful, -1 if any error occured.
 */
SFCAPI int sf_write(uint32 fd,FILE* file);

/*
 * @fn	SFCAPI int sf_mkdir(char* name)
 * 
 * @brief	Creates a new directory inside the SFC File.
 *			The new directory is child of the current working directory.
 * 
 * @author	Roberto Estrada Casarrubios
 * 
 * @param	name The name of the new directory. 
 * 
 * @return	0 if succesful, -1 if any error occured.
 */
SFCAPI int sf_mkdir(char* name);

/*
 * @fn	SFCAPI int sf_chdir(char* name)
 * 
 * @brief	Changes the current working directory (cwd)
 * 
 * @author	Roberto Estrada Casarrubios
 * 
 * @param	path	The full path of the new current working directory.
 *					This path must be specified in UNIX-Like style.
 *					i.e: "/foo/bar"
 * 
 * @return	0 if succesful, -1 if any error occured.
 */
SFCAPI int sf_chdir(char* path);

/*
 * @fn	SFCAPI int libdestroy()
 * 
 * @brief	Call to end the library usage
 * 
 * @author	Roberto Estrada Casarrubios
 * @date	18/06/2009
 * 
 * @return	0 if succesful, -1 if any error occured.
 */

SFCAPI int libdestroy();

#ifdef __cplusplus
}
#endif

/* SFCLIB_H */
#endif
